package cn.mymall.entity;

import cn.mymall.constant.OrderStatusConstant;
import cn.mymall.constant.PayConstant;
import cn.mymall.constant.PayMethodConstant;
import cn.mymall.util.DateUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.sql.Timestamp;

/**
 * <p>
 *
 * </p>
 *
 * @author liqilun
 * @since 2024-03-23
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class TradeOrder extends Model {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    private String tradeno;

    private String mobile;

    private BigDecimal orderAmount;

    private BigDecimal settleAmount;

    private BigDecimal discount;

    private BigDecimal cashPay;

    private Timestamp addTime;

    private Timestamp paymentTime;

    private Timestamp expireTime;

    private Integer memberId;

    private String payStatus;

    private String orderStatus;

    private String paymethod;

    /**
     * 外部交易流水号
     */
    private String payseqno;

    private String otherinfo;

    private String ip;

    private BigDecimal expressFee;

    private String status;

    public String gainPaymethodText() {
        return PayMethodConstant.getPaymethod(paymethod);
    }

    public String gainOrderStatusText() {
        return OrderStatusConstant.ORDER_STATUS_MAP.get(orderStatus);
    }

    public String gainPayStatusText() {
        if (StringUtils.equals(PayConstant.NOTPAY, this.payStatus)) {
            Timestamp curtime = DateUtil.getCurFullTimestamp();
            if (this.expireTime != null && this.expireTime.before(curtime)) {
                return "超时取消";
            }
        }
        return PayConstant.PAY_MAP.get(this.payStatus);
    }
}
